package hk.m4s.lr.repair.test.ui.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import hk.m4s.lr.repair.test.R;
import hk.m4s.lr.repair.test.model.JiangliModel;

/**
 * Created by qi.wang on 2017/3/16.
 */

public class SelectListAdapter extends BaseAdapter {
    List<JiangliModel> list = new ArrayList<JiangliModel>();
    Context context;
    LayoutInflater inflater;
    public int flag=-1;
    public SelectListAdapter(Context context, List<JiangliModel> data) {
        this.context = context;
        this.list = data;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.list_item_select, parent, false);
            holder.jiangli_name = (TextView) convertView.findViewById(R.id.jiangli_name);
            holder.imageView=(ImageView) convertView.findViewById(R.id.jiangli_on);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        JiangliModel deviceModel = list.get(position);
        try {
            holder.jiangli_name.setText(deviceModel.getName());
            if (flag==position) {
                holder.jiangli_name.setTextColor(Color.parseColor("#fe9c00"));
                holder.imageView.setImageResource(R.mipmap.couponcheckd);
            } else {
                holder.jiangli_name.setTextColor(Color.parseColor("#777777"));
                holder.imageView.setImageResource(R.mipmap.couponcheck);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return convertView;
    }

    public static class ViewHolder {
        TextView jiangli_name;
        ImageView imageView;
    }

}
